package com.tpolteam.tpol.tpol2019.demo.mvp

import java.lang.ref.Reference
import java.lang.ref.WeakReference

/**
 * @author Liangbo.Xu
 * @create 2020/7/13
 * @Describe desc
 */
abstract class BasePresenter<T> {
    protected var mViewRef: Reference<T>? = null

    val a: String? = "asda"

    fun attachView(view: T) {
        mViewRef = WeakReference<T>(view)
    }

    fun getView(): T? {
        return mViewRef?.get()
    }

    fun isViewAttached(): Boolean {
        return mViewRef != null && mViewRef?.get() != null
    }

    fun detachView() {
        mViewRef?.let {
            mViewRef!!.clear()
            mViewRef = null
        }
    }


}